package org.wattdepot.cli.commands;

import org.junit.Test;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This class tests the list summary command of the CommandLineInterface's actual commands.
 * @author David Mau
 */
public class TestCommandListSummary {
  
  /**
   * Tests the normal operation of the list sources command.
   */
  @Test
  public void testListSummary() {
    // Create a new list sources command object.
    ListSummaryCommand command = new ListSummaryCommand(null);
    // Create a new List to store the args for known data
    List<String> args = Arrays.asList("SIM_KAHE_1");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );
    
    // Make sure that the information output is correct.
    assertTrue("Checking Subsources", sourceOutput.contains("Subsources: "));
    assertTrue("Checking Description", sourceOutput.contains("Description: Kahe 1"));
    assertTrue("Checking Owner", sourceOutput.contains("Owner: oscar@wattdepot.org"));
    assertTrue("Checking Properties", sourceOutput.contains("Properties: " +
        "(carbonIntensity: 1744) (fuelType: LSFO)"));
    assertTrue("Checking Earliest Data", 
        sourceOutput.contains("Earliest data: 2009-10-25T00:00:00.000-10:00"));
    assertTrue("Checking Total Data Points", sourceOutput.contains("Total data points: 6528"));
    
    // Try another known data
    args = Arrays.asList("SIM_OAHU_GRID");
    sourceOutput = command.doCommand( args );

    // Make sure that the information output is correct. 
    assertTrue("Checking Subsources", 
        sourceOutput.contains("Subsources: SIM_KAHE, SIM_KAHE, SIM_WAIAU, SIM_HONOLULU, SIM_IPP"));
    assertTrue("Checking Description", sourceOutput.contains("Description: Virtual " +
        "resource for all Oahu power plants."));
    assertTrue("Checking Owner", sourceOutput.contains("Owner: oscar@wattdepot.org"));
    assertTrue("Checking Properties", sourceOutput.contains("Properties: "));
    assertTrue("Checking Earliest Data", 
        sourceOutput.contains("Earliest data: 2009-10-25T00:00:00.000-10:00"));
    assertTrue("Checking Total Data Points", sourceOutput.contains("Total data points: 117504"));
  }
  
  /**
   * Test bad source detection for the list summary command.
   */
  @Test
  public void testSummaryBadSource() {
 // Create a new list summary command object.
    ListSummaryCommand command = new ListSummaryCommand(null);
    // Create a new List to store the args for known data
    List<String> args = Arrays.asList("BLAH");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the right error returned.
    assertTrue("Checking for correct response to bad source", sourceOutput
        .contains(WattDepotCliCommand.resourceNotFound));
  }
  
  /**
   * Tests to see if the list summary command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new list summary command object.
    ListSummaryCommand command = new ListSummaryCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess ListSource argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the list summary command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new list summary command object.
    ListSummaryCommand command = new ListSummaryCommand(null);
    // Create a new List to store the args
    List<String> args = new ArrayList<String>();
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking ListSummaryStamp handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
